package com.dlwx.parttimetalent.views;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;
import android.widget.NumberPicker;
import android.widget.TextView;

import com.dlwx.parttimetalent.R;
import com.dlwx.parttimetalent.inter.GetAgeInter;
import com.flyco.dialog.widget.base.BaseDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/11/21.
 */

public class IncomeFilterDialog extends BaseDialog {
    @BindView(R.id.datepicker)
    DatePicker datepicker;
    @BindView(R.id.tv_confirm)
    TextView tvConfirm;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_all)
    TextView tvAll;
    @BindView(R.id.tv_income_salary)
    TextView tvIncomeSalary;
    @BindView(R.id.tv_income_tuiguang)
    TextView tvIncomeTuiguang;
    @BindView(R.id.tv_withdraw)
    TextView tvWithdraw;
    @BindView(R.id.tv_expense)
    TextView tvExpense;
    private Context context;
    private GetAgeInter inter;
    private int type=0;


    public IncomeFilterDialog(Context context, GetAgeInter inter) {
        super(context);
        this.context = context;
        this.inter=inter;
    }

    @Override
    public View onCreateView() {
        widthScale(0.90f);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_income, null);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void setUiBeforShow() {
        chooseType(0);
        datepicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    }

    @OnClick({R.id.tv_all, R.id.tv_income_salary, R.id.tv_income_tuiguang, R.id.tv_withdraw
            , R.id.tv_expense,R.id.tv_confirm, R.id.tv_cancel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_confirm:
                inter.getAge(type,0,0,datepicker.getYear()+"-"+(datepicker.getMonth()+ 1)+"-"+datepicker.getDayOfMonth()+"");
                this.dismiss();
                break;
            case R.id.tv_cancel:
                this.dismiss();
                break;
            case R.id.tv_all:
                chooseType(0);
                break;
            case R.id.tv_income_salary:
                chooseType(1);
                break;
            case R.id.tv_income_tuiguang:
                chooseType(2);
                break;
            case R.id.tv_withdraw:
                chooseType(3);
                break;
            case R.id.tv_expense:
                chooseType(4);
                break;
        }
    }

    private void chooseType(int i) {
        type=i;
        int red=ContextCompat.getColor(context,R.color.colorAccent);
        int grey=ContextCompat.getColor(context,R.color.second_textcolor);
        tvAll.setTextColor(grey);
        tvIncomeSalary.setTextColor(grey);
        tvIncomeTuiguang.setTextColor(grey);
        tvWithdraw.setTextColor(grey);
        tvExpense.setTextColor(grey);
        switch (i){
            case 0:
                tvAll.setTextColor(red);
                break;
            case 1:
                tvIncomeSalary.setTextColor(red);
                break;
            case 2:
                tvIncomeTuiguang.setTextColor(red);
                break;
            case 3:
                tvWithdraw.setTextColor(red);
                break;
            case 4:
                tvExpense.setTextColor(red);
                break;
        }
    }
}
